# $Id: PKGBUILD 90006 2013-05-06 19:36:18Z foutrelis $
# Contributor: John Sowiak <john@archlinux.org>
# Contributor: tobias <tobias@archlinux.org>
# Maintainer: Sven-Hendrik Haase <sh@lutzhaase.com>

# Sometimes blender.org takes some time to release patch releases and because Arch users
# are impatient, we sometimes need to build from svn directly.

_svnrev=56125

pkgname=blender
pkgver=2.66a
[[ -n $_svnrev ]] && pkgver=2.66a.$_svnrev
pkgrel=2
epoch=7
pkgdesc="A fully integrated 3D graphics creation suite"
arch=('i686' 'x86_64')
license=('GPL')
url="http://www.blender.org"
depends=('libpng' 'libtiff' 'openexr' 'python' 'desktop-file-utils'
         'shared-mime-info' 'hicolor-icon-theme' 'xdg-utils' 'glew'
         'freetype2' 'openal' 'ffmpeg' 'fftw' 'boost-libs' 'opencollada'
         'openimageio' 'libsndfile' 'jack' 'opencolorio' 'openshadinglanguage')
makedepends=('cmake' 'boost' 'cuda' 'subversion' 'mesa')
optdepends=('cuda: cycles renderer cuda support')
options=(!strip)
install=blender.install
if [[ -n $_svnrev ]]; then
  source=("${pkgname}-${pkgver}::svn+https://svn.blender.org/svnroot/bf-blender/trunk/blender#revision=${_svnrev}")
  md5sums=(SKIP)
else
  source=(http://download.blender.org/source/$pkgname-$pkgver.tar.gz)
  md5sums=('dde8211818e35b00a1c01a11efef4533')
fi

build() {
  cd "$srcdir/$pkgname-$pkgver"

  mkdir build
  cd build

  [[ $CARCH == i686 ]] && ENABLESSE2="-DSUPPORT_SSE2_BUILD=OFF"
  [[ $CARCH == i686 ]] && BUILDCUDA="OFF" || BUILDCUDA="ON"

  cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=Release \
    -DWITH_INSTALL_PORTABLE=OFF \
    -DWITH_PYTHON_INSTALL=OFF \
    -DWITH_OPENCOLLADA=ON \
    -DOPENIMAGEIO_ROOT_DIR=/usr \
    -DWITH_GAMEENGINE=ON \
    -DWITH_JACK=ON \
    -DWITH_PLAYER=ON \
    -DWITH_CODEC_FFMPEG=ON \
    -DWITH_CODEC_SNDFILE=ON \
    -DWITH_CYCLES=ON \
    -DWITH_CYCLES_CUDA_BINARIES=$BUILDCUDA \
    -DWITH_CYCLES_OSL=ON \
    -DCUDA_TOOLKIT_ROOT_DIR=/opt/cuda/ \
    -DWITH_FFTW3=ON \
    -DWITH_MOD_OCEANSIM=ON \
    -DPYTHON_VERSION=3.3 \
    -DPYTHON_LIBPATH=/usr/lib \
    -DPYTHON_LIBRARY=python3.3m \
    -DPYTHON_INCLUDE_DIRS=/usr/include/python3.3m \
    $ENABLESSE2

  make $MAKEFLAGS

  make
}

package() {
  cd "$srcdir/$pkgname-$pkgver/build"

  make DESTDIR="${pkgdir}" install
  python -m compileall "${pkgdir}/usr/share/blender"
}
